<%@ page contentType="text/html; charset=utf-8" import="com.running.crm.model.Mms,com.running.crm.model.MmsContent,java.util.*,com.running.util.StringUtils,com.running.util.FileOperator"%><%
Map mms = (Map)request.getAttribute("mms");
List<Map> smilContents = (List<Map>)request.getAttribute("smilContents");
List<Map> mmsContents = (List<Map>)request.getAttribute("mmsContents");
String rootDir = config.getServletContext().getRealPath("/").replaceAll("\\\\","/");	//根目录
if (rootDir.endsWith("/")) {
	rootDir = rootDir.substring(0,rootDir.length()-1);
}
String mmsDstNum = StringUtils.varFormat(request.getParameter("phoneNo"));
%>
<html>
<head>
<script language="javascript">
var returnUrl;
var tmpImgFileDir = new Array();
var tmpImgFileName = new Array();
var tmpImgFileSize = new Array();
//var tmpVoiFileDir = new Array();
//var tmpVoiFileName = new Array();
//var tmpVoiFileSize = new Array();
var tmpMmsText = new Array();
var tmpFrameTime = new Array();

window.onload = function Init(){
	
	document.oForm.frameCount.value="<%=smilContents.size()%>";
	loadMmsContent();
	setFrame(document.oForm.frameCount.value);
    
}


function setFrame(iFrameCount){
	var objMmsContainer = document.getElementById('oFrameSpan');
	if (objMmsContainer) {
		if (objMmsContainer.children)
			oldFrameCount = objMmsContainer.children.length;
		for (var i=1;i<=oldFrameCount;i++) {
			tmpImgFileDir[i-1] = document.all("imgFileDir"+i).value;
			tmpImgFileName[i-1] = document.all("imgFileName"+i).value;
			tmpImgFileSize[i-1] = document.all("imgFileSize"+i).value;
			tmpMmsText[i-1] = document.all("mmsText"+i).value;
			tmpFrameTime[i-1] = document.all("frameTime"+i).value;
		}
	}
	var sFrame = "";
	for(var i=1;i<=parseInt(iFrameCount);i++){
		if (tmpImgFileDir.length>=i) {
			sFrame += buildMmsFrame(i,tmpImgFileDir[i-1],tmpImgFileName[i-1],tmpImgFileSize[i-1],tmpMmsText[i-1],tmpFrameTime[i-1],"N");
		} else {//一切新增
			sFrame += buildMmsFrame(i,"","","","","","N");
		}
	}
	document.all("oFrameSpan").innerHTML = sFrame;
}

function loadMmsContent() {
<%
int i = 0;
for(Map smilContent:smilContents){
	out.println("tmpImgFileDir["+i+"]=''");
	out.println("tmpImgFileName["+i+"]=''");
	out.println("tmpImgFileSize["+i+"]=''");
	out.println("tmpMmsText["+i+"]=''");
	out.println("tmpFrameTime["+i+"]='10'");
	for (Map mmsContent : mmsContents) {
		if (StringUtils.varFormat(String.valueOf(smilContent.get("imgFileName"))).equals(mmsContent.get("file_name"))) {
			out.println("tmpImgFileDir["+i+"]='"+mmsContent.get("file_dir")+"'");
			out.println("tmpImgFileName["+i+"]='"+mmsContent.get("file_name")+"'");
			out.println("tmpImgFileSize["+i+"]='"+mmsContent.get("file_size")+"'");
		}
		if (StringUtils.varFormat(String.valueOf(smilContent.get("txtFileName"))).equals(mmsContent.get("file_name"))) {
			if (FileOperator.exists(rootDir + "/" + mmsContent.get("file_dir") + "/" + mmsContent.get("file_name"))) {
				out.println("tmpMmsText["+i+"]='"+FileOperator.read(rootDir + "/" + mmsContent.get("file_dir") + "/" + mmsContent.get("file_name")).replace("\r\n","\\r\\n").replace("'","\\'")+"'");
			}
		}
	}
	if (!StringUtils.varFormat(String.valueOf(smilContent.get("frameTime"))).equals("")) {
		out.println("tmpFrameTime["+i+"]='"+StringUtils.varFormat(String.valueOf(smilContent.get("frameTime")))+"'");
	}
	i++;
}	
%>
}


</script>
</head>
<body>

<form name="oForm" onsubmit="return beforeSubmit(this)" method="POST" action="">
<input type="hidden" name="frameCount" value="1"/>
<table id="FormTable">

<tr><td>
	<fieldset>
		<legend>彩信预览</legend>
		<span id="oFrameSpan"></span>
	</fieldset>		
</td></tr>

</table>
</form>
</body>
</html>